package com.hxzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzy.common.util.WaimaiThreadLocal;
import com.hxzy.controller.admin.dictdata.req.DictDataReq;
import com.hxzy.entity.SysDictData;
import com.hxzy.service.SysDictDataService;
import com.hxzy.mapper.SysDictDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author Administrator
* @description 针对表【sys_dict_data(字典数据表)】的数据库操作Service实现
* @createDate 2023-06-28 16:38:45
*/
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData>
    implements SysDictDataService{

    @Autowired
    private SysDictDataMapper sysDictDataMapper;


    @Override
    public PageInfo<SysDictData> search(DictDataReq req) {
        return PageHelper.startPage(req.getPage(),req.getSize())
                .doSelectPageInfo(()->{

                    sysDictDataMapper.search(req);
                });
    }

    @Override
    public boolean delete(Long[] ids) {
        SysDictData sysDictData=new SysDictData();
        sysDictData.setStatus("1");
        sysDictData.setUpdateBy(WaimaiThreadLocal.getName());
        sysDictData.setUpdateTime(new Date());

        LambdaQueryWrapper<SysDictData> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.in(SysDictData::getId,ids);

        boolean update = super.update(sysDictData, queryWrapper);
        return update;
    }

    /**
     * 更新dict_type的值
     * @param oldValue
     * @param newValue
     * @return
     */
    @Override
    public boolean updateDictType(String oldValue, String newValue) {
        return this.sysDictDataMapper.updateDictType(oldValue,newValue)>0;
    }

    @Override
    public List<SysDictData> searchAllData() {
        return this.sysDictDataMapper.searchAllData();
    }
}




